﻿using System.Text;

namespace CodeParser.Tokens
{
    public class Int
        : TokenParser
    {

        public override Token GetTokenAt(string source, int index)
        {
            var i = index;
            var sourceLength = source.Length;
            var token = new StringBuilder();
            var currentChar = ' ';
            while (i < sourceLength)
            {
                currentChar = source[i++];
                if (currentChar < '0' || currentChar > '9')
                {
                    break;
                }
                token.Append(currentChar);
            }
            if (token.Length > 0)
            {
                if (currentChar == 'u' || currentChar == 'l' || currentChar == 'h')
                    token.Append(currentChar);
                return new Token() { Index = index, Type = TokenType.LiteralInt, Value = token.ToString() };
            }
            return null;
        }

    }
}
